﻿using System;
using System.Collections.Generic;
using MemoryPack;
#if UNITY_EDITOR
using Sirenix.OdinInspector;
#endif

namespace Hsenl {
    [Serializable]
    [MemoryPackable(GenerateType.NoGenerate)]
    public abstract partial class SelectionTarget : Component {
        
#if UNITY_EDITOR
        [ShowInInspector]
#endif
        [MemoryPackInclude, MemoryPackAllowSerialize]
        public ISelectionTargetVariable Variable { get; private set; }
        
        public T SetVariable<T>(T t) where T : ISelectionTargetVariable {
            this.Variable = t;
            return t;
        }

        public T GetVariable<T>() where T : ISelectionTargetVariable {
            if (this.Variable is T t)
                return t;

            return default(T);
        }
        
        protected override void OnDisable() {
            this.Variable?.OnDisable();
        }

        protected override void OnDestroy() {
            this.Variable?.Dispose();
        }
    }
}